package sri.proiect.search;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

import sri.proiect.index.DatabaseIndexManager;
import sri.proiect.index.IndexManager;
import sri.proiect.models.Hotel;
import sri.proiect.utils.DBColumn;

/**
 * This class is used to search the 
 * Lucene index and return search results
 */
public class BasicSearcher extends AbstractSearcher{
	
	private static BasicSearcher instance;
	
	private BasicSearcher() {
		
	}
	
	public static BasicSearcher instance() {
		if (instance == null) {
			instance = new BasicSearcher();
		}
		
		return instance;
	}
    public List<Hotel> search(String searchWord){
    	List<Hotel> searchResult = new ArrayList<Hotel>();
    	if (false == ckeckOrCreateIndex()) {
    		return searchResult;
    	}
    	
    	IndexSearcher indexSearcher = getIndexSearcher();
        
    	QueryParser queryParser = new QueryParser(Version.LUCENE_CURRENT, "fulltext", analyzer);
    	Query query = null;
    	try {
			query = queryParser.parse(searchWord);
			searchForHotels(searchResult, query);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
    	return searchResult;
    }
}
